package com.ordersystem.controller;

import com.ordersystem.domain.Purview;
import com.ordersystem.domain.Result;
import com.ordersystem.service.PurviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : asus1020
 * @version : [v1.0]
 * @className : PurviewController
 * @description : [描述说明该类的功能]
 * @createTime : [2022/3/25 16:09]
 * @updateUser : asus1020
 * @updateTime : [2022/3/25 16:09]
 * @updateRemark : [描述说明本次修改内容]
 */
@RestController
@RequestMapping("/purview")
public class PurviewController {
    @Autowired
    private PurviewService purviewService;

    @GetMapping("/getMenuList")//获取菜单列表
    public Result getMenuList(){
        Result result = new Result();
        List<Purview> allMenuList = purviewService.getAllMenuList();
        if (allMenuList!=null){
            result.setData(allMenuList);
            result.setMessage("查找菜单成功");
            result.setStatus(200);
        }else {
            result.setStatus(500);
            result.setMessage("查询菜单失败");
        }
        return result;

    }

    @GetMapping("/getPurviewList")//获取所有权限列表
    public Result getPurviewList(){
        Result result = new Result();
        List<Purview> purviewList = purviewService.findAllPurviewList();
        if (purviewList!=null){
            result.setMessage("查询所有权限成功");
            result.setStatus(200);
            result.setData(purviewList);
        }else {
            result.setStatus(500);
            result.setMessage("查询所有权限失败");
        }
        return result;

    }

    @GetMapping("/getPurviewByPids")//查询角色所有权限
    public Result getPurviewByPids(String pids){
        Result result = new Result();
        List<Purview> allPurviewByPids = purviewService.findAllPurviewByPids(pids);
        if (allPurviewByPids==null){
            result.setStatus(500);
            result.setMessage("查询角色权限失败");
        }else {
            result.setStatus(200);
            result.setData(allPurviewByPids);
            result.setMessage("查询角色权限成功");
        }
        return result;
    }
}
